class Solution {
public:
    int addDigits(int num) {
        while (num / 10 != 0) {
            int temp_num = 0;
            while (num != 0) {
                temp_num += num % 10;
                num /= 10;
            }
            num = temp_num;
        }
        return num;
    }
};